// https : // iai.sh.cn/problem/442
#include <bits/stdc++.h>
using namespace std;

int a[300001];
long long sum[3000001];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= n; i++)
    sum[i] = sum[i - 1] + a[i];

  long long king = 0x3f3f3f3f3f3f3f3f;
  // int king= INT_MAX;
  long long L = 0; // L的初始值

  // 求 R的 初始值
  long long R = 0;
  for (int i = 2; i <= n; i++)
    R = R + (i - 1) * a[i];

  // 不断的迭代
  for (int i = 2; i <= n - 1; i++) {
    L = L + sum[i - 1];
    R = R - (sum[n] - sum[i - 1]);
    king = min(king, abs(R - L));
  }
  cout << king;
  return 0;
}